// app.js
App({
  //渐入，渐出实现 
  show: function (that, param, opacity,time) {
    var animation = wx.createAnimation({
      //持续时间800ms
      duration: time?time:800,
      timingFunction: 'ease',
    });
    //var animation = this.animation
    animation.opacity(opacity).step()
    //将param转换为key
    var json = '{"' + param + '":""}'
    json = JSON.parse(json);
    json[param] = animation.export()
    //设置动画
    that.setData(json)
  },

  //滑动渐入渐出
  slideupshow: function (that, param, px, opacity) {
    var animation = wx.createAnimation({
      duration: 800,
      timingFunction: 'ease',
    });
    animation.translateY(px).opacity(opacity).step()
    //将param转换为key
    var json = '{"' + param + '":""}'
    json = JSON.parse(json);
    json[param] = animation.export()
    //设置动画
    that.setData(json)
  },

  //向右滑动渐入渐出
  sliderightshow: function (that, param, px, opacity) {
    var animation = wx.createAnimation({
      duration: 800,
      timingFunction: 'ease',
    });
    animation.translateX(px).opacity(opacity).step()
    //将param转换为key
    var json = '{"' + param + '":""}'
    json = JSON.parse(json);
    json[param] = animation.export()
    //设置动画
    that.setData(json)
  },
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    if (!wx.cloud) {
      console.error('请使用 2.2.3 或以上的基础库以使用云能力')
    } else {
      wx.cloud.init({
        // env 参数说明：
        //   env 参数决定接下来小程序发起的云开发调用（wx.cloud.xxx）会默认请求到哪个云环境的资源
        //   此处请填入环境 ID, 环境 ID 可打开云控制台查看
        //   如不填则使用默认环境（第一个创建的环境）
        env: 'cloud1-3gfrf2kaa51df13c',
        traceUser: true,
      })
    }
    // 登录
    // wx.login({
    //   success: res => {
    //     console.log(res)
    //     this.globalData.code = res.code
    //     // 发送 res.code 到后台换取 openId, sessionKey, unionId
    //   }
    // })

    wx.cloud.callFunction({
      name: 'login',
      data: {},
      success: res => {
        console.log(res)
        this.globalData.openId = res.result.userInfo.openId
        // 用户登录获取openid之后 绑定分销关系api
        // 异步否则无法获取openid
      },
      fail: err => {
        wx.showToast({
          "title": err,
          "icon": "none"
        });
        return;
      }
    });

    //设置导航栏
    //获取菜单按钮的布局位置信息
    let menuButtonObject = wx.getMenuButtonBoundingClientRect();
    //获取系统信息
    wx.getSystemInfo({
      success: res => {
        //状态栏的高度
        let statusBarHeight = res.statusBarHeight,
          //胶囊按钮与顶部的距离
          navTop = menuButtonObject.top,
          navHeight = statusBarHeight + menuButtonObject.height + (menuButtonObject.top - statusBarHeight) * 2;
        this.globalData.navHeight = navHeight; //导航栏高度
        this.globalData.navTop = navTop; //胶囊按钮与顶部的距离
        this.globalData.jnheight = menuButtonObject.height; //胶囊的高度
        this.globalData.jnwidth = menuButtonObject.width; //胶囊的宽度
      },
      fail(err) {
        console.log(err);
      }
    })
  },
  globalData: {
    userInfo: null,
    domain: 'https://docs.spacetimesc.com/',
    // domain: 'http://localhost:18081/', 
    successCode: 0,
    navHeight: 0,
    navTop: 0,
    jnheight: 0,
    jnwidth: 0,
    openId:'',
    theme:'',
    // 全局模板Ids
    tmplIds: ['YgFksfqNSncg4AeYrmdZuCk0QSn2kJknREys4ha3tCk']
  }
})
const app = getApp()